package com.polaris.live.im.db.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.polaris.live.im.db.entity.MessageExcludeEntity

/**
 * 消息去重
 *
 * @author Created by lucas on 2023/10/21 10:34
 * @since 1.0.0
 */
@Dao
interface MessageExcludeEntityDao {

    //插入数据
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(entity: MessageExcludeEntity)

    //判断消息是否存在
    @Query("select exists(select 1 from message_exclude where user_id = :userId and msg_id = :msgId)")
    suspend fun existsByMsgId(userId: Long, msgId: String): Boolean

    //清理冗余数据
    @Query("delete from message_exclude where timestamp < :timestamp")
    suspend fun clearRedundancy(timestamp: Long)

}